1. Technical Field of the Invention
This invention pertains to communications across networks between computers of different architectures. In particular, this invention provides templates enabling cross platform communication of complex structure-based messages across networks.
2. Background Art
Heretofore, dissimilar systems must communicate over networks using mutually agreed-upon message formats which do not take any system-specific characteristics such as word size or byte order into account. Two aspects of the problem which cause difficulty in such network communications are (1) structure packing, and (2) byte ordering.
Structure packing is a problem because not all compilers support #pragma pack(1). #pragma is an instruction to a compiler which the compiler may ignore, it is merely a suggestion. The "pack(1)" argument suggests to the compiler that it compress all data structures so no empty space exists, and the "(1)" refers one byte boundaries. A 32 bit computer generally aligns data on four byte boundaries. However, the "pack(1)" instruction will, if accepted by the computer, cause, for example, a 32 bit computer to behave like an 8 bit (that is, 1 byte) computer. No Macintosh compiler supports this option, for instance, and many UNIX and AIX compilers also lack this feature. The lack of such an option means that a programmer can not easily control the sizes of multi-part message structures due to differences in the native word size and word alignment rules on particular CPU architectures.
Byte ordering is a problem because different CPU architectures store multi-byte values in different physical memory orders. For instance, Intel-family CPUs store integers in the opposite byte order from PowerPC CPUs. This means that messages containing multi-byte components are difficult to handle in a portable fashion. C code source can be portable, but it is not automatically assured to be portable between computer platforms. C code source can be considered portable only if features that break portability are not used. For example, portability is broken by use of different integer lengths, such as 16 vs 32. The C language allows portability, but portability is easy to break. (In contrast, the ADA language guarantees portability.)
In the past, programmers dealt with problem (1) structure packing by declaring all structures used in inter-machine communication as simple arrays of bytes, then programming intricate and ugly `byte-stuffing` logic to pack and unpack the arrays for communication. They dealt with problem (2) byte ordering by using macros or functions which pushed the CPU-architecture-dependent logic into header files or libraries which were still system-dependent (non-portable). While these techniques worked, they resulted in source code which was cryptic and very difficult to maintain.
Consequently, there is a need in the art for a system and method which enables the writing of portable communications software in, for example, C or C++ which will work property in a wide variety of target environments with only a mechanical recompile of the common source code.
It is an object of the invention to provide an improved system and method for structure packing and byte ordering.
It is a further object of the invention to provide an improved system and method for writing portable communications software that will work properly in a wide variety of target environments.
It is a further object of the invention to provide an improved system and method for translating between native data structures on arbitrary machines and specific message structures on communication media.
It is a further object of the invention to provide an improved system and method for translating data structures such that the byte order and word alignment on a native machine is translated as needed into the byte order and word alignment required in a communication media.